package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.response.LeadListItemBean;
import com.ygxsk.carhome.utils.CommUtils;

import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2024/2/21  15:16
 * @Description:添加潜客信息 到客户档案之中的
 */
public class LeadManMemberAdapter extends BaseQuickAdapter<LeadListItemBean, BaseViewHolder> {

    public LeadManMemberAdapter(int layoutResId, @Nullable List<LeadListItemBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, LeadListItemBean leadListItemBean) {

        if (leadListItemBean != null) {

            //客户姓名
            String customerName = leadListItemBean.getCustomerName();

            //客户的手机号
            String customerPhone = leadListItemBean.getCustomerPhone();

            //客户的？
            //是否被勾中
            int isChecked = leadListItemBean.getIsChecked();


            //头像
            //人员的头像
            ImageView imageViewPersonLeadMember = (ImageView) baseViewHolder.findView(R.id.imageviewpersonleadmember);
            //人员名称
            TextView textViewNameInLeadMember = (TextView) baseViewHolder.findView(R.id.textviewnameinleadmember);
            //中间的分割线条
            TextView textViewSplitInLeadMember = (TextView) baseViewHolder.findView(R.id.textviewsplitinleadmember);
            //手机号信息
            TextView textViewPersonInStaionName = (TextView) baseViewHolder.findView(R.id.textviewpersoninstaionname);

            //被选中的图片内容
            CheckBox checkBoxInLeadMember = (CheckBox) baseViewHolder.findView(R.id.checkboxinleadmember);

            //底部的一条横向，最后一条数据的时候 是隐藏的
            TextView textViewLineInLeadMember = (TextView) baseViewHolder.findView(R.id.textviewlineinleadmember);


            //真实名字
            CommUtils.setText(textViewNameInLeadMember, customerName);
            //手机号信息
            CommUtils.setText(textViewPersonInStaionName, customerPhone);

            //加载图片:因为这里是png图片，所以这里用png占位
//            Glide.with(getContext())//
//                    .load("")//默认是空“”
//                    .centerInside()//
//                    .error(R.drawable.vector_personl)//
//                    .placeholder(R.drawable.iconmri)//
//                    .fallback(R.drawable.vector_personl)//
//                    .into(imageViewPersonLeadMember);//

            //如果 手机号信息 是空的，那么不展示分隔符号
            if (TextUtils.isEmpty(customerPhone)) {
                textViewSplitInLeadMember.setVisibility(View.GONE);
            } else {
                textViewSplitInLeadMember.setVisibility(View.VISIBLE);
            }

            //最后一条数据 底部的分割线条隐藏
            if (getItemPosition(leadListItemBean) == getData().size() - 1) {
                textViewLineInLeadMember.setVisibility(View.GONE);
            } else {
                textViewLineInLeadMember.setVisibility(View.VISIBLE);
            }

            if (isChecked == 1) {//表示选中
                checkBoxInLeadMember.setChecked(true);
            } else if (isChecked == 0) {
                checkBoxInLeadMember.setChecked(false);
            }


        }

    }
}
